﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Subgurim.Controles;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void populate_Maps()
    {

        int value = public_Lv.Items.Count;
        while (value > 0)
        {
            value = value - 1;

            string lm = ((Label)public_Lv.Items[value].FindControl("Landmarklabel")).Text;
            string state = ((Label)public_Lv.Items[value].FindControl("State_Namelabel")).Text;
            string city = ((Label)public_Lv.Items[value].FindControl("CityLabel")).Text;
            string type = ((Label)public_Lv.Items[value].FindControl("TypeLabel")).Text;
            string fullAddr = lm + ", " + city + ", " +state; //combines all the locations to give to the geocode requester.
            
            //Basics of the Map. 
            GMap.Width = 700;
            GMap.Add(new GControl(GControl.preBuilt.LargeMapControl));
            GeoCode geographycode = GMap.geoCodeRequest(fullAddr);
            GLatLng gLngLat = new GLatLng(geographycode.Placemark.coordinates.lat, geographycode.Placemark.coordinates.lng);

            GeoCode australia_geocode = GMap.geoCodeRequest("Australia");
            GLatLng aus_gLngLat = new GLatLng(australia_geocode.Placemark.coordinates.lat, australia_geocode.Placemark.coordinates.lng);

            //int zoom = Int32.Parse(GMapType.GTypes.Normal.ToString()); // figure out this zoom shit later..
            GMap.setCenter(aus_gLngLat, 3); // Sets the center of the Map.
            
            //This part is for the Marker
            GIcon icon = new GIcon();
            string url = HttpContext.Current.Request.Url.AbsoluteUri.Replace("%20", " ");
            string link = url.Replace(HttpContext.Current.Request.Url.Segments[2], "");
            icon.image =link+"Styles/icons/icon"+value+".png";
            icon.shadow = link + "Styles/icons/icon" + value + "-shadow.png";
            icon.iconSize = new GSize(32, 32);
            icon.shadowSize = new GSize(56, 32);
            icon.iconAnchor = new GPoint(16, 32);
            icon.infoWindowAnchor = new GPoint(16,0);
            GMarkerOptions mOpts = new GMarkerOptions();
            mOpts.icon = icon;

            GMarker lm_marker = new GMarker(gLngLat, mOpts);
            GMap.addGMarker(lm_marker);
            
            //This part is for the Info Window
            GInfoWindow window = new GInfoWindow(lm_marker, "Type: " + type + "<br/> Location: " + lm + ", " + city + ", " + state);
            GMap.addInfoWindow(window);          
        }
    }


    protected void  public_Lv_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void public_Lv_Databound(object sender, EventArgs e)
    {
        populate_Maps();
    }

    protected void rb_states_List_Changed(object sender, EventArgs e)
    {
        string location = rb_states_List.SelectedValue;
        GeoCode new_geocode = GMap.geoCodeRequest(location + ",Australia");
        GLatLng new_gLngLat = new GLatLng(new_geocode.Placemark.coordinates.lat, new_geocode.Placemark.coordinates.lng);

        //int zoom = Int32.Parse(GMapType.GTypes.Normal.ToString()); // figure out this zoom shit later..
        GMap.setCenter(new_gLngLat, getZoom(location)); // Sets the center of the Map.
    }

    protected int getZoom(string location)
    {
        int zoom_val = 0;
        if (location == "AUSTRALIA")
        {
            zoom_val = 3;
        }
        else
        {
            zoom_val = 5;
        }

        return zoom_val;
    }

    protected void link_text_Click(object sender, EventArgs e)
    {
        Response.Redirect("all_incidents.aspx");
    }
}